/*
 * @Version: 0.0.1
 * @Author: ider
 * @Date: 2021-01-06 13:08:23
 * @LastEditors: ider
 * @LastEditTime: 2021-03-01 14:50:44
 * @Description:
 */
package model

import (
	"fmt"
	"strings"
	"time"

	"gorm.io/gorm"
)

// DoubleBall 双色球采集后保存的结构
type DoubleBall struct {
	Qihao        string    `gorm:"primaryKey;" json:"qihao"`
	OpenDate     time.Time `json:"opendate"`
	RedBall      string    `json:"redball"`
	RedBallOrder string    `json:"redballorder"`
	BlueBall     string    `json:"blueball"`
	TotalSales   int64     `json:"totalsales"`
	OneCount     int64     `json:"onecount"`
	OneAward     int64     `json:"oneaward"`
	TwoCount     int64     `json:"twocount"`
	TwoAward     int64     `json:"twoaward"`
	ThreeCount   int64     `json:"threecount"`
	ThreeAward   int64     `json:"threeaward"`
	Jackpot      int64     `json:"jackpot"`
}

// UserDoubleBallForever 用户长期投注
type UserDoubleBallForever struct {
	ID        uint           `gorm:"primaryKey" json:"id"`
	CreatedAt time.Time      `json:"createdAt"`
	UpdatedAt time.Time      `gorm:"index" json:"-"`
	DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
	UserID    uint           `gorm:"index" json:"userid"`
	Disabled  bool           `gorm:"not null;default:false;" json:"disabled"` //是否暂时禁用
	Comment   string         `json:"comment"`                                 //用户备注
	RedBall   string         `json:"redball"`
	BlueBall  string         `json:"blueball"`
	Last      int            `json:"last"` //跟踪次数
}

// UserDoubleBall 用户投注数
type UserDoubleBall struct {
	ID        uint           `gorm:"primaryKey" json:"id"`
	CreatedAt time.Time      `json:"createdAt"`
	UpdatedAt time.Time      `gorm:"index" json:"-"`
	DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
	UserID    uint           `gorm:"index" json:"userid"`
	Comment   string         `json:"comment"`
	Qihao     string         `json:"qihao"`
	RedBall   string         `json:"redball"`
	BlueBall  string         `json:"blueball"`
	IsOpen    bool           `gorm:"not null;default:false;index" json:"isOpen,omitempty"` //是否计算开奖
	IsBot     bool           `gorm:"not null;default:false;" json:"isBot,omitempty"`       //是否是机器自动更新的长期投注
	A         int            `json:"a,omitempty"`
	B         int            `json:"b,omitempty"`
	C         int            `json:"c,omitempty"`
	D         int            `json:"d,omitempty"`
	E         int            `json:"e,omitempty"`
	F         int            `json:"f,omitempty"`
	Award     string         `gorm:"-" json:"award,omitempty"` //历史中奖，实时计算，用来表达历史中奖
}

// ToString to string
func (c *UserDoubleBall) ToString() []string {
	var retS []string
	if c.A > 0 {
		retS = append(retS, fmt.Sprintf("一等奖 %d 注", c.A))
	}
	if c.B > 0 {
		retS = append(retS, fmt.Sprintf("二等奖 %d 注", c.B))
	}
	if c.C > 0 {
		retS = append(retS, fmt.Sprintf("三等奖 %d 注", c.C))
	}
	if c.D > 0 {
		retS = append(retS, fmt.Sprintf("四等奖 %d 注", c.D))
	}
	if c.E > 0 {
		retS = append(retS, fmt.Sprintf("五等奖 %d 注", c.E))
	}
	if c.F > 0 {
		retS = append(retS, fmt.Sprintf("六等奖 %d 注", c.F))
	}
	return retS
}

// GetAward 打印中奖情况
func (c *UserDoubleBall) GetAward() {
	c.Award = strings.Join(c.ToString(), ",")
}
